package com.apps.config;


import com.apps.Interceptor.GlobalInterceptor;
import com.apps.config.UPloadConfig;
import com.apps.sworld.sConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.*;

/**
 * @description: web拦截配置
 * @author: YuXD
 * @create: 2019-02-11 12:27
 **/
@Configuration
public class WebAuthConfig implements sConfig {

    @Autowired(required = false)
    private UPloadConfig uploadConfig;

    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            /**
             * 跨域支持
             * @param registry
             */
            @Override
            public void addCorsMappings(CorsRegistry registry) {
//                registry.addMapping("/**");
            }

            @Override
            public void addInterceptors(InterceptorRegistry registry) {
                // 只对非静态资源进行全局拦截
                GlobalInterceptor globalInterceptor = new GlobalInterceptor();
                registry.addInterceptor(globalInterceptor);//注册全局拦截器
            }

            @Override
            public void addResourceHandlers(ResourceHandlerRegistry registry)
            {
                //配置上传资源访问路径
                //registry.addResourceHandler("/"+ IKupaUpLoadConfig.getRootpath()+"/**").addResourceLocations("file:"+ IKupaUpLoadConfig.getSysRootpath()+"/");
                //配置ueditor上传资源访问路径
                registry.addResourceHandler(uploadConfig.getResource()).addResourceLocations("file:"+uploadConfig.getRootpath());
                //配置静态资源访问路径
                registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
                //配置swagger路径
                registry.addResourceHandler("/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
                registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
            }

            /**
             * 配置首页
             * @param registry
             */
//            @Override
//            public void addViewControllers(ViewControllerRegistry registry)
//            {
//                //设置主页
//                registry.addViewController("/").setViewName("/page/open/member/home.html");
//                //设置优先级
//                registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
//            }
        };
    }

}
